/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * EmployeesDialog.java
 *
 * Created on 19-May-2009, 14:12:39
 */
package TimeRecording.forms;

import TimeRecording.TimeRecordingView;
import TimeRecording.business.EmployeeUtilities;
import TimeRecording.business.PeriodCalculations;
import TimeRecording.enums.AuthorisationLevel;
import TimeRecording.enums.EventType;
import TimeRecording.tables.Employee;
import TimeRecording.tables.Event;
import TimeRecording.tables.WorkingPattern;
import TimeRecording.tables.WorkingSummary;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.persistence.EntityManager;
import javax.swing.JOptionPane;
import org.jdesktop.application.Action;

/**
 *
 * @author cbegg
 */
public class EmployeesDialog extends javax.swing.JDialog {

    private final static Logger LOGGER = Logger.getLogger(
            EmployeesDialog.class.getName());
    
    private static final long serialVersionUID = 1L;

    // <editor-fold defaultstate="collapsed" desc="selectedEmployee + Getter & Setter">
    private Employee selectedEmployee;

    public Employee getSelectedEmployee() {
        return selectedEmployee;
    }

    public void setSelectedEmployee(Employee selectedEmployee) {

        Employee oldSelectedEmployee = this.selectedEmployee;
        this.selectedEmployee = selectedEmployee;
        firePropertyChange("selectedEmployee",
                oldSelectedEmployee, selectedEmployee);

        setEmployeeSelected(selectedEmployee != null);
    } // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="employeeSelected + Getter & Setter">
    private boolean employeeSelected = false;

    public boolean getEmployeeSelected() {
        return employeeSelected;
    }

    public void setEmployeeSelected(boolean employeeSelected) {
        boolean oldEmployeeSelected = this.employeeSelected;
        this.employeeSelected = employeeSelected;
        firePropertyChange("employeeSelected",
                oldEmployeeSelected, employeeSelected);
    } // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="selectedWorkingPatternDetail + Getter & Setter">
    private WorkingPattern selectedWorkingPatternDetail;

    public WorkingPattern getSelectedWorkingPatternDetail() {
        return selectedWorkingPatternDetail;
    }

    public void setSelectedWorkingPatternDetail(
            WorkingPattern selectedWorkingPatternDetail) {
        
        WorkingPattern oldSelectedWorkingPatternDetail =
                this.selectedWorkingPatternDetail;
        this.selectedWorkingPatternDetail = selectedWorkingPatternDetail;        
        firePropertyChange("selectedWorkingPatternDetail",
                oldSelectedWorkingPatternDetail, selectedWorkingPatternDetail);

        setWorkingPatternDetailSelected(selectedWorkingPatternDetail != null);
    } // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="workingPatterDetailSelected + Getter & Setter">
    private boolean workingPatternDetailSelected = false;

    public boolean getWorkingPatternDetailSelected() {
        return workingPatternDetailSelected;
    }

    public void setWorkingPatternDetailSelected(boolean workingPatternDetailSelected) {
        boolean oldWorkingPatternDetailSelected = this.workingPatternDetailSelected;
        this.workingPatternDetailSelected = workingPatternDetailSelected;
        firePropertyChange("workingPatternDetailSelected",
                oldWorkingPatternDetailSelected, workingPatternDetailSelected);
    } // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="supervisorLoggedIn + Getter & Setter">
    private boolean supervisorLoggedIn = false;

    public boolean getSupervisorLoggedIn() {
        return supervisorLoggedIn;
    }

    public void setSupervisorLoggedIn(boolean supervisorLoggedIn) {
        boolean oldSupervisorLoggedIn = this.supervisorLoggedIn;
        this.supervisorLoggedIn = supervisorLoggedIn;
        firePropertyChange("supervisorLoggedIn",
                oldSupervisorLoggedIn, supervisorLoggedIn);
    } //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc="loggedInEmployee + Getter & Setter">
    private Employee loggedInEmployee;

    public Employee getLoggedInEmployee() {
        return loggedInEmployee;
    }

    public void setLoggedInEmployee(Employee loggedInEmployee) {
        this.loggedInEmployee = loggedInEmployee;
    } // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="entityManager Getter & Setter">
    public EntityManager getEntityManager() {
        return entityManager;
    }

    public void setEntityManager(EntityManager entityManager) {
        EntityManager oldEntityManager = this.entityManager;
        this.entityManager = entityManager;
        firePropertyChange("entityManager", oldEntityManager, entityManager);
    } // </editor-fold>

    /** Creates new form EmployeesDialog */
    @SuppressWarnings("OverridableMethodCallInConstructor")
    public EmployeesDialog(TimeRecordingView parent, boolean modal) {

        super(parent.getFrame(), modal);
        myParent = parent;
        initComponents();

        // Check for Supervisor logged in
        setSupervisorLoggedIn(myParent.isSupervisorLoggedIn());
        setLoggedInEmployee(myParent.getLoggedInEmployee());

        // If "joe public" is logged in then only allow him to see
        // his own details (might even want to suppress this).

        // TODO - This is dubious; may just wish to suppress this dialog
        
        if (!getSupervisorLoggedIn()) {
            employeeList.clear();
            if (loggedInEmployee != null) {
                employeeList.add(loggedInEmployee);
                employeeTable.setRowSelectionInterval(0, 0);	// only one row allowed
            }
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        entityManager = myParent.getEntityManager();
        activeEmployeesQuery = java.beans.Beans.isDesignTime() ? null : TimeRecording.tables.Employee.getActiveEmployeesQuery(entityManager);
        allEmployeesQuery = java.beans.Beans.isDesignTime() ? null : Employee.getEmployeesQuery(entityManager)
        ;
        employeeList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections.observableList(activeEmployeesQuery.getResultList());
        timeCellRenderer = new TimeRecording.forms.renderers.TimeCellRenderer();
        dateCellRenderer = new TimeRecording.forms.renderers.DateCellRenderer();
        employeeQuery = activeEmployeesQuery;
        authorisationLevelConverter = new TimeRecording.enums.AuthorisationLevelConverter();
        employeeStatusConverter = new TimeRecording.enums.EmployeeStatusConverter();
        employeesPanel = new javax.swing.JPanel();
        masterScrollPane = new javax.swing.JScrollPane();
        employeeTable = new javax.swing.JTable();
        forenameLabel = new javax.swing.JLabel();
        forenameText = new javax.swing.JTextField();
        surnameLabel = new javax.swing.JLabel();
        surnameText = new javax.swing.JTextField();
        payrollReferenceLabel = new javax.swing.JLabel();
        payrollReferenceText = new javax.swing.JTextField();
        statusLabel = new javax.swing.JLabel();
        statusText = new javax.swing.JTextField();
        usernameLabel = new javax.swing.JLabel();
        usernameText = new javax.swing.JTextField();
        authorisationLevelLabel = new javax.swing.JLabel();
        authorisationLevelText = new javax.swing.JTextField();
        employeeButtonPanel = new javax.swing.JPanel();
        newEmployeeButton = new javax.swing.JButton();
        editEmployeeButton = new javax.swing.JButton();
        deleteEmployeeButton = new javax.swing.JButton();
        badgesLabel = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        includeDeletedButton = new javax.swing.JToggleButton();
        contractPanel = new javax.swing.JPanel();
        patternScrollPane = new javax.swing.JScrollPane();
        patternDescriptionTextArea = new javax.swing.JTextArea();
        annualLeaveDaysLabel = new javax.swing.JLabel();
        annualLeaveDays = new javax.swing.JFormattedTextField();
        annualLeaveHoursLabel = new javax.swing.JLabel();
        annualLeaveHours = new javax.swing.JFormattedTextField();
        alertsSuppressedCheckBox = new javax.swing.JCheckBox();
        flexitimeCheckBox = new javax.swing.JCheckBox();
        editPatternButton = new javax.swing.JButton();
        absenceSummaryPanel = new TimeRecording.forms.AbsenceSummaryPanel();
        workingPatternPanel = new javax.swing.JPanel();
        workingPatternPane = new javax.swing.JScrollPane();
        workingPatternTable = new javax.swing.JTable();
        patternButtonPanel = new javax.swing.JPanel();
        newPeriodButton = new javax.swing.JButton();
        editPeriodButton = new javax.swing.JButton();
        deletePeriodButton = new javax.swing.JButton();
        hoursPerWeekLabel = new javax.swing.JLabel();
        contractedPeriodField = new javax.swing.JFormattedTextField();
        hoursPerDayLabel = new javax.swing.JLabel();
        hoursPerDay = new javax.swing.JFormattedTextField();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(TimeRecording.TimeRecordingApp.class).getContext().getResourceMap(EmployeesDialog.class);
        timeCellRenderer.setText(resourceMap.getString("timeCellRenderer.text")); // NOI18N
        timeCellRenderer.setName("timeCellRenderer"); // NOI18N

        dateCellRenderer.setText(resourceMap.getString("dateCellRenderer.text")); // NOI18N
        dateCellRenderer.setName("dateCellRenderer"); // NOI18N

        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });
        getContentPane().setLayout(new java.awt.GridBagLayout());

        employeesPanel.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createEmptyBorder(8, 8, 0, 8), javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("employeesPanel.border.insideBorder.title")))); // NOI18N
        employeesPanel.setMinimumSize(new java.awt.Dimension(400, 216));
        employeesPanel.setName("employeesPanel"); // NOI18N
        employeesPanel.setLayout(new java.awt.GridBagLayout());

        masterScrollPane.setName("masterScrollPane"); // NOI18N
        masterScrollPane.setPreferredSize(new java.awt.Dimension(400, 200));

        employeeTable.setAutoCreateRowSorter(true);
        employeeTable.setName("employeeTable"); // NOI18N

        org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, employeeList, employeeTable);
        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${employeeId}"));
        columnBinding.setColumnName("Employee Id");
        columnBinding.setColumnClass(Integer.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${forename}"));
        columnBinding.setColumnName("Forename");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${surname}"));
        columnBinding.setColumnName("Surname");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${payrollReference}"));
        columnBinding.setColumnName("Payroll Reference");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${status}"));
        columnBinding.setColumnName("Status");
        columnBinding.setColumnClass(TimeRecording.enums.EmployeeStatus.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${statusTime}"));
        columnBinding.setColumnName("Status Time");
        columnBinding.setColumnClass(java.util.Date.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${username}"));
        columnBinding.setColumnName("Username");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${authorisationLevel}"));
        columnBinding.setColumnName("Authorisation Level");
        columnBinding.setColumnClass(TimeRecording.enums.AuthorisationLevel.class);
        columnBinding.setEditable(false);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${selectedEmployee}"), employeeTable, org.jdesktop.beansbinding.BeanProperty.create("selectedElement"));
        bindingGroup.addBinding(binding);

        masterScrollPane.setViewportView(employeeTable);
        employeeTable.getColumnModel().getColumn(0).setPreferredWidth(20);
        employeeTable.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("employeeTable.columnModel.title7")); // NOI18N
        employeeTable.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("employeeTable.columnModel.title0")); // NOI18N
        employeeTable.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("employeeTable.columnModel.title2")); // NOI18N
        employeeTable.getColumnModel().getColumn(4).setHeaderValue(resourceMap.getString("employeeTable.columnModel.title3")); // NOI18N
        employeeTable.getColumnModel().getColumn(5).setHeaderValue(resourceMap.getString("employeeTable.columnModel.title4")); // NOI18N
        employeeTable.getColumnModel().getColumn(6).setHeaderValue(resourceMap.getString("employeeTable.columnModel.title5")); // NOI18N
        employeeTable.getColumnModel().getColumn(7).setHeaderValue(resourceMap.getString("employeeTable.columnModel.title6")); // NOI18N

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 8;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 8, 5, 8);
        employeesPanel.add(masterScrollPane, gridBagConstraints);

        forenameLabel.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        forenameLabel.setLabelFor(forenameText);
        forenameLabel.setText(resourceMap.getString("forenameLabel.text")); // NOI18N
        forenameLabel.setName("forenameLabel"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(4, 8, 5, 4);
        employeesPanel.add(forenameLabel, gridBagConstraints);

        forenameText.setEditable(false);
        forenameText.setMaximumSize(null);
        forenameText.setMinimumSize(new java.awt.Dimension(100, 20));
        forenameText.setName("forenameText"); // NOI18N
        forenameText.setPreferredSize(new java.awt.Dimension(100, 20));

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${selectedEmployee.forename}"), forenameText, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 25.0;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 5, 4);
        employeesPanel.add(forenameText, gridBagConstraints);

        surnameLabel.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        surnameLabel.setLabelFor(surnameText);
        surnameLabel.setText(resourceMap.getString("surnameLabel.text")); // NOI18N
        surnameLabel.setName("surnameLabel"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(4, 8, 4, 4);
        employeesPanel.add(surnameLabel, gridBagConstraints);

        surnameText.setEditable(false);
        surnameText.setMaximumSize(null);
        surnameText.setMinimumSize(new java.awt.Dimension(100, 20));
        surnameText.setName("surnameText"); // NOI18N
        surnameText.setPreferredSize(new java.awt.Dimension(100, 20));

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${selectedEmployee.surname}"), surnameText, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 25.0;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        employeesPanel.add(surnameText, gridBagConstraints);

        payrollReferenceLabel.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        payrollReferenceLabel.setLabelFor(payrollReferenceText);
        payrollReferenceLabel.setText(resourceMap.getString("payrollReferenceLabel.text")); // NOI18N
        payrollReferenceLabel.setName("payrollReferenceLabel"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        employeesPanel.add(payrollReferenceLabel, gridBagConstraints);

        payrollReferenceText.setEditable(false);
        payrollReferenceText.setMaximumSize(null);
        payrollReferenceText.setMinimumSize(new java.awt.Dimension(100, 20));
        payrollReferenceText.setName("payrollReferenceText"); // NOI18N
        payrollReferenceText.setPreferredSize(new java.awt.Dimension(100, 20));

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${selectedEmployee.payrollReference}"), payrollReferenceText, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 5;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 25.0;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 5, 4);
        employeesPanel.add(payrollReferenceText, gridBagConstraints);

        statusLabel.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        statusLabel.setLabelFor(statusText);
        statusLabel.setText(resourceMap.getString("statusLabel.text")); // NOI18N
        statusLabel.setName("statusLabel"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 5, 4);
        employeesPanel.add(statusLabel, gridBagConstraints);

        statusText.setEditable(false);
        statusText.setMaximumSize(null);
        statusText.setMinimumSize(new java.awt.Dimension(100, 20));
        statusText.setName("statusText"); // NOI18N
        statusText.setPreferredSize(new java.awt.Dimension(100, 20));

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, this, org.jdesktop.beansbinding.ELProperty.create("${selectedEmployee.status}"), statusText, org.jdesktop.beansbinding.BeanProperty.create("text"));
        binding.setConverter(employeeStatusConverter);
        bindingGroup.addBinding(binding);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 5;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 25.0;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 5, 4);
        employeesPanel.add(statusText, gridBagConstraints);

        usernameLabel.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        usernameLabel.setLabelFor(usernameText);
        usernameLabel.setText(resourceMap.getString("usernameLabel.text")); // NOI18N
        usernameLabel.setName("usernameLabel"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(4, 8, 4, 4);
        employeesPanel.add(usernameLabel, gridBagConstraints);

        usernameText.setEditable(false);
        usernameText.setMaximumSize(null);
        usernameText.setMinimumSize(new java.awt.Dimension(100, 20));
        usernameText.setName("usernameText"); // NOI18N
        usernameText.setPreferredSize(new java.awt.Dimension(100, 20));

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${selectedEmployee.username}"), usernameText, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 25.0;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        employeesPanel.add(usernameText, gridBagConstraints);

        authorisationLevelLabel.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        authorisationLevelLabel.setLabelFor(authorisationLevelText);
        authorisationLevelLabel.setText(resourceMap.getString("authorisationLevelLabel.text")); // NOI18N
        authorisationLevelLabel.setName("authorisationLevelLabel"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        employeesPanel.add(authorisationLevelLabel, gridBagConstraints);

        authorisationLevelText.setEditable(false);
        authorisationLevelText.setMaximumSize(null);
        authorisationLevelText.setMinimumSize(new java.awt.Dimension(100, 20));
        authorisationLevelText.setName("authorisationLevelText"); // NOI18N
        authorisationLevelText.setPreferredSize(new java.awt.Dimension(100, 20));

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, this, org.jdesktop.beansbinding.ELProperty.create("${selectedEmployee.authorisationLevel}"), authorisationLevelText, org.jdesktop.beansbinding.BeanProperty.create("text"));
        binding.setConverter(authorisationLevelConverter);
        bindingGroup.addBinding(binding);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 25.0;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        employeesPanel.add(authorisationLevelText, gridBagConstraints);

        employeeButtonPanel.setMaximumSize(null);
        employeeButtonPanel.setName("employeeButtonPanel"); // NOI18N
        employeeButtonPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT, 5, 0));

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(TimeRecording.TimeRecordingApp.class).getContext().getActionMap(EmployeesDialog.class, this);
        newEmployeeButton.setAction(actionMap.get("newEmployeeButton")); // NOI18N
        newEmployeeButton.setText(resourceMap.getString("newEmployeeButton.text")); // NOI18N
        newEmployeeButton.setName("newEmployeeButton"); // NOI18N
        employeeButtonPanel.add(newEmployeeButton);

        editEmployeeButton.setAction(actionMap.get("editEmployeeButton")); // NOI18N
        editEmployeeButton.setText(resourceMap.getString("editEmployeeButton.text")); // NOI18N
        editEmployeeButton.setName("editEmployeeButton"); // NOI18N
        employeeButtonPanel.add(editEmployeeButton);

        deleteEmployeeButton.setAction(actionMap.get("deleteEmployeeButton")); // NOI18N
        deleteEmployeeButton.setText(resourceMap.getString("deleteEmployeeButton.text")); // NOI18N
        deleteEmployeeButton.setName("deleteEmployeeButton"); // NOI18N
        employeeButtonPanel.add(deleteEmployeeButton);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = 6;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 3);
        employeesPanel.add(employeeButtonPanel, gridBagConstraints);

        badgesLabel.setText(resourceMap.getString("badgesLabel.text")); // NOI18N
        badgesLabel.setName("badgesLabel"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 6;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        employeesPanel.add(badgesLabel, gridBagConstraints);

        jScrollPane1.setMinimumSize(new java.awt.Dimension(100, 23));
        jScrollPane1.setName("jScrollPane1"); // NOI18N
        jScrollPane1.setPreferredSize(new java.awt.Dimension(100, 23));

        jList1.setBackground(resourceMap.getColor("jList1.background")); // NOI18N
        jList1.setName("jList1"); // NOI18N
        jList1.setPreferredSize(new java.awt.Dimension(100, 23));

        org.jdesktop.beansbinding.ELProperty eLProperty = org.jdesktop.beansbinding.ELProperty.create("${selectedEmployee.badges}");
        org.jdesktop.swingbinding.JListBinding jListBinding = org.jdesktop.swingbinding.SwingBindings.createJListBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, eLProperty, jList1);
        jListBinding.setDetailBinding(org.jdesktop.beansbinding.ELProperty.create("${badgeId}"));
        bindingGroup.addBinding(jListBinding);

        jScrollPane1.setViewportView(jList1);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 7;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 25.0;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 8);
        employeesPanel.add(jScrollPane1, gridBagConstraints);

        includeDeletedButton.setAction(actionMap.get("includeDeletedClicked")); // NOI18N
        includeDeletedButton.setText(resourceMap.getString("includeDeletedButton.text")); // NOI18N
        includeDeletedButton.setName("includeDeletedButton"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 8, 4, 4);
        employeesPanel.add(includeDeletedButton, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        getContentPane().add(employeesPanel, gridBagConstraints);

        contractPanel.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createEmptyBorder(0, 8, 0, 8), javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("contractPanel.border.insideBorder.title")))); // NOI18N
        contractPanel.setMinimumSize(new java.awt.Dimension(695, 72));
        contractPanel.setName("contractPanel"); // NOI18N
        contractPanel.setLayout(new java.awt.GridBagLayout());

        patternScrollPane.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        patternScrollPane.setName("patternScrollPane"); // NOI18N
        patternScrollPane.setPreferredSize(new java.awt.Dimension(400, 100));

        patternDescriptionTextArea.setColumns(20);
        patternDescriptionTextArea.setEditable(false);
        patternDescriptionTextArea.setName("patternDescriptionTextArea"); // NOI18N

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, employeeTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.workingPatternsMaster.patternDescription}"), patternDescriptionTextArea, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        patternScrollPane.setViewportView(patternDescriptionTextArea);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 7;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(5, 8, 5, 8);
        contractPanel.add(patternScrollPane, gridBagConstraints);

        annualLeaveDaysLabel.setText(resourceMap.getString("annualLeaveDaysLabel.text")); // NOI18N
        annualLeaveDaysLabel.setName("annualLeaveDaysLabel"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(4, 8, 4, 4);
        contractPanel.add(annualLeaveDaysLabel, gridBagConstraints);

        annualLeaveDays.setEditable(false);
        annualLeaveDays.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0.00"))));
        annualLeaveDays.setText(resourceMap.getString("annualLeaveDays.text")); // NOI18N
        annualLeaveDays.setMinimumSize(new java.awt.Dimension(60, 20));
        annualLeaveDays.setName("annualLeaveDays"); // NOI18N
        annualLeaveDays.setPreferredSize(new java.awt.Dimension(60, 20));

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${selectedEmployee.workingPatternsMaster.annualLeaveAllowanceInDays}"), annualLeaveDays, org.jdesktop.beansbinding.BeanProperty.create("value"));
        bindingGroup.addBinding(binding);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        contractPanel.add(annualLeaveDays, gridBagConstraints);

        annualLeaveHoursLabel.setText(resourceMap.getString("annualLeaveHoursLabel.text")); // NOI18N
        annualLeaveHoursLabel.setName("annualLeaveHoursLabel"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        contractPanel.add(annualLeaveHoursLabel, gridBagConstraints);

        annualLeaveHours.setEditable(false);
        annualLeaveHours.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0.00"))));
        annualLeaveHours.setText(resourceMap.getString("annualLeaveHours.text")); // NOI18N
        annualLeaveHours.setMinimumSize(new java.awt.Dimension(60, 20));
        annualLeaveHours.setName("annualLeaveHours"); // NOI18N
        annualLeaveHours.setPreferredSize(new java.awt.Dimension(60, 20));

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${selectedEmployee.workingPatternsMaster.annualLeaveAllowance}"), annualLeaveHours, org.jdesktop.beansbinding.BeanProperty.create("value"));
        bindingGroup.addBinding(binding);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        contractPanel.add(annualLeaveHours, gridBagConstraints);

        alertsSuppressedCheckBox.setText(resourceMap.getString("alertsSuppressedCheckBox.text")); // NOI18N
        alertsSuppressedCheckBox.setEnabled(false);
        alertsSuppressedCheckBox.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);
        alertsSuppressedCheckBox.setName("alertsSuppressedCheckBox"); // NOI18N

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, employeeTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.workingPatternsMaster.alertSuppression}"), alertsSuppressedCheckBox, org.jdesktop.beansbinding.BeanProperty.create("selected"));
        bindingGroup.addBinding(binding);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 4, 5, 4);
        contractPanel.add(alertsSuppressedCheckBox, gridBagConstraints);

        flexitimeCheckBox.setText(resourceMap.getString("flexitimeCheckBox.text")); // NOI18N
        flexitimeCheckBox.setEnabled(false);
        flexitimeCheckBox.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);
        flexitimeCheckBox.setName("flexitimeCheckBox"); // NOI18N

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, employeeTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.workingPatternsMaster.flexitime}"), flexitimeCheckBox, org.jdesktop.beansbinding.BeanProperty.create("selected"));
        bindingGroup.addBinding(binding);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 5;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.insets = new java.awt.Insets(5, 4, 5, 4);
        contractPanel.add(flexitimeCheckBox, gridBagConstraints);

        editPatternButton.setAction(actionMap.get("editContractSummary")); // NOI18N
        editPatternButton.setText(resourceMap.getString("editPatternButton.text")); // NOI18N
        editPatternButton.setMaximumSize(new java.awt.Dimension(170, 23));
        editPatternButton.setMinimumSize(new java.awt.Dimension(170, 23));
        editPatternButton.setName("editPatternButton"); // NOI18N
        editPatternButton.setPreferredSize(new java.awt.Dimension(170, 23));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 6;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST;
        gridBagConstraints.insets = new java.awt.Insets(5, 4, 5, 8);
        contractPanel.add(editPatternButton, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        getContentPane().add(contractPanel, gridBagConstraints);

        absenceSummaryPanel.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createEmptyBorder(0, 8, 0, 8), javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("absenceSummaryPanel.border.insideBorder.title")))); // NOI18N
        absenceSummaryPanel.setName("absenceSummaryPanel"); // NOI18N

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, employeeTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.workingPatternsMaster}"), absenceSummaryPanel, org.jdesktop.beansbinding.BeanProperty.create("workingPatternMaster"));
        bindingGroup.addBinding(binding);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        getContentPane().add(absenceSummaryPanel, gridBagConstraints);

        workingPatternPanel.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createEmptyBorder(0, 8, 0, 8), javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("workingPatternPanel.border.insideBorder.title")))); // NOI18N
        workingPatternPanel.setMaximumSize(new java.awt.Dimension(32767, 350));
        workingPatternPanel.setMinimumSize(new java.awt.Dimension(400, 150));
        workingPatternPanel.setName("workingPatternPanel"); // NOI18N
        workingPatternPanel.setLayout(new java.awt.GridBagLayout());

        workingPatternPane.setName("workingPatternPane"); // NOI18N
        workingPatternPane.setPreferredSize(new java.awt.Dimension(400, 100));

        workingPatternTable.setAutoCreateRowSorter(true);
        workingPatternTable.setName("workingPatternTable"); // NOI18N

        eLProperty = org.jdesktop.beansbinding.ELProperty.create("${selectedEmployee.workingPatterns}");
        jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, eLProperty, workingPatternTable);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${patternType}"));
        columnBinding.setColumnName("Pattern Type");
        columnBinding.setColumnClass(TimeRecording.enums.PatternType.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${patternStartDate}"));
        columnBinding.setColumnName("Pattern Start Date");
        columnBinding.setColumnClass(java.util.Date.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${patternEndDate}"));
        columnBinding.setColumnName("Pattern End Date");
        columnBinding.setColumnClass(java.util.Date.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${periodStart}"));
        columnBinding.setColumnName("Period Start");
        columnBinding.setColumnClass(java.util.Date.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${periodEnd}"));
        columnBinding.setColumnName("Period End");
        columnBinding.setColumnClass(java.util.Date.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${dailyHours}"));
        columnBinding.setColumnName("Daily Hours");
        columnBinding.setColumnClass(Float.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${weeklyHours}"));
        columnBinding.setColumnName("Weekly Hours");
        columnBinding.setColumnClass(Float.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${monday}"));
        columnBinding.setColumnName("Monday");
        columnBinding.setColumnClass(Boolean.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${tuesday}"));
        columnBinding.setColumnName("Tuesday");
        columnBinding.setColumnClass(Boolean.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${wednesday}"));
        columnBinding.setColumnName("Wednesday");
        columnBinding.setColumnClass(Boolean.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${thursday}"));
        columnBinding.setColumnName("Thursday");
        columnBinding.setColumnClass(Boolean.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${friday}"));
        columnBinding.setColumnName("Friday");
        columnBinding.setColumnClass(Boolean.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${saturday}"));
        columnBinding.setColumnName("Saturday");
        columnBinding.setColumnClass(Boolean.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${sunday}"));
        columnBinding.setColumnName("Sunday");
        columnBinding.setColumnClass(Boolean.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${flexiPattern}"));
        columnBinding.setColumnName("Flexi Pattern");
        columnBinding.setColumnClass(Boolean.class);
        columnBinding.setEditable(false);
        jTableBinding.setSourceNullValue(java.util.Collections.emptyList());
        jTableBinding.setSourceUnreadableValue(java.util.Collections.emptyList());
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${selectedWorkingPatternDetail}"), workingPatternTable, org.jdesktop.beansbinding.BeanProperty.create("selectedElement"));
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, employeeTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), workingPatternTable, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        workingPatternPane.setViewportView(workingPatternTable);
        workingPatternTable.getColumnModel().getColumn(0).setPreferredWidth(90);
        workingPatternTable.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("workingPatternTable.columnModel.title0")); // NOI18N
        workingPatternTable.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("workingPatternTable.columnModel.title1")); // NOI18N
        workingPatternTable.getColumnModel().getColumn(1).setCellRenderer(dateCellRenderer);
        workingPatternTable.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("workingPatternTable.columnModel.title2")); // NOI18N
        workingPatternTable.getColumnModel().getColumn(2).setCellRenderer(dateCellRenderer);
        workingPatternTable.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("workingPatternTable.columnModel.title3")); // NOI18N
        workingPatternTable.getColumnModel().getColumn(3).setCellRenderer(timeCellRenderer);
        workingPatternTable.getColumnModel().getColumn(4).setHeaderValue(resourceMap.getString("workingPatternTable.columnModel.title4")); // NOI18N
        workingPatternTable.getColumnModel().getColumn(4).setCellRenderer(timeCellRenderer);
        workingPatternTable.getColumnModel().getColumn(5).setHeaderValue(resourceMap.getString("workingPatternTable.columnModel.title5")); // NOI18N
        workingPatternTable.getColumnModel().getColumn(6).setHeaderValue(resourceMap.getString("workingPatternTable.columnModel.title6")); // NOI18N
        workingPatternTable.getColumnModel().getColumn(7).setPreferredWidth(50);
        workingPatternTable.getColumnModel().getColumn(7).setHeaderValue(resourceMap.getString("workingPatternTable.columnModel.title7")); // NOI18N
        workingPatternTable.getColumnModel().getColumn(8).setPreferredWidth(50);
        workingPatternTable.getColumnModel().getColumn(8).setHeaderValue(resourceMap.getString("workingPatternTable.columnModel.title8")); // NOI18N
        workingPatternTable.getColumnModel().getColumn(9).setPreferredWidth(50);
        workingPatternTable.getColumnModel().getColumn(9).setHeaderValue(resourceMap.getString("workingPatternTable.columnModel.title9")); // NOI18N
        workingPatternTable.getColumnModel().getColumn(10).setPreferredWidth(50);
        workingPatternTable.getColumnModel().getColumn(10).setHeaderValue(resourceMap.getString("workingPatternTable.columnModel.title10")); // NOI18N
        workingPatternTable.getColumnModel().getColumn(11).setPreferredWidth(50);
        workingPatternTable.getColumnModel().getColumn(11).setHeaderValue(resourceMap.getString("workingPatternTable.columnModel.title11")); // NOI18N
        workingPatternTable.getColumnModel().getColumn(12).setPreferredWidth(50);
        workingPatternTable.getColumnModel().getColumn(12).setHeaderValue(resourceMap.getString("workingPatternTable.columnModel.title12")); // NOI18N
        workingPatternTable.getColumnModel().getColumn(13).setPreferredWidth(50);
        workingPatternTable.getColumnModel().getColumn(13).setHeaderValue(resourceMap.getString("workingPatternTable.columnModel.title13")); // NOI18N
        workingPatternTable.getColumnModel().getColumn(14).setPreferredWidth(50);
        workingPatternTable.getColumnModel().getColumn(14).setHeaderValue(resourceMap.getString("workingPatternTable.columnModel.title14")); // NOI18N

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 5;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 0.67;
        gridBagConstraints.insets = new java.awt.Insets(0, 8, 5, 8);
        workingPatternPanel.add(workingPatternPane, gridBagConstraints);

        patternButtonPanel.setMaximumSize(null);
        patternButtonPanel.setName("patternButtonPanel"); // NOI18N
        patternButtonPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT, 5, 0));

        newPeriodButton.setAction(actionMap.get("newPeriodButton")); // NOI18N
        newPeriodButton.setText(resourceMap.getString("newPeriodButton.text")); // NOI18N
        newPeriodButton.setName("newPeriodButton"); // NOI18N
        patternButtonPanel.add(newPeriodButton);

        editPeriodButton.setAction(actionMap.get("editPeriodButton")); // NOI18N
        editPeriodButton.setText(resourceMap.getString("editPeriodButton.text")); // NOI18N
        editPeriodButton.setName("editPeriodButton"); // NOI18N
        patternButtonPanel.add(editPeriodButton);

        deletePeriodButton.setAction(actionMap.get("deletePeriodButton")); // NOI18N
        deletePeriodButton.setText(resourceMap.getString("deletePeriodButton.text")); // NOI18N
        deletePeriodButton.setName("deletePeriodButton"); // NOI18N

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${workingPatternDetailSeleced}"), deletePeriodButton, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        patternButtonPanel.add(deletePeriodButton);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST;
        gridBagConstraints.weightx = 50.0;
        gridBagConstraints.insets = new java.awt.Insets(4, 0, 5, 3);
        workingPatternPanel.add(patternButtonPanel, gridBagConstraints);

        hoursPerWeekLabel.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        hoursPerWeekLabel.setText(resourceMap.getString("hoursPerWeekLabel.text")); // NOI18N
        hoursPerWeekLabel.setName("hoursPerWeekLabel"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(4, 8, 4, 4);
        workingPatternPanel.add(hoursPerWeekLabel, gridBagConstraints);

        contractedPeriodField.setEditable(false);
        contractedPeriodField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0.00"))));
        contractedPeriodField.setText(resourceMap.getString("contractedPeriodField.text")); // NOI18N
        contractedPeriodField.setName("contractedPeriodField"); // NOI18N

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, employeeTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.workingPatternsMaster.hoursWorkedPerWeek}"), contractedPeriodField, org.jdesktop.beansbinding.BeanProperty.create("value"));
        bindingGroup.addBinding(binding);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 25.0;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        workingPatternPanel.add(contractedPeriodField, gridBagConstraints);

        hoursPerDayLabel.setText(resourceMap.getString("hoursPerDayLabel.text")); // NOI18N
        hoursPerDayLabel.setName("hoursPerDayLabel"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        workingPatternPanel.add(hoursPerDayLabel, gridBagConstraints);

        hoursPerDay.setEditable(false);
        hoursPerDay.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0.00"))));
        hoursPerDay.setName("hoursPerDay"); // NOI18N

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, employeeTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.workingPatternsMaster.hoursWorkedPerDay}"), hoursPerDay, org.jdesktop.beansbinding.BeanProperty.create("value"));
        bindingGroup.addBinding(binding);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 25.0;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        workingPatternPanel.add(hoursPerDay, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        getContentPane().add(workingPatternPanel, gridBagConstraints);

        bindingGroup.bind();

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-881)/2, (screenSize.height-657)/2, 881, 657);
    }// </editor-fold>//GEN-END:initComponents

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        myParent.hideEmployeesDialog();
    }//GEN-LAST:event_formWindowClosing

    @Action(enabledProperty = "employeeSelected")
    public void editEmployeeButton() {

        // Check the employee details into the editor for editing
        EmployeeEditor editor = new EmployeeEditor(this, false);
        editor.setCurrentRecord(selectedEmployee);
        editor.setEditMode(true);
        editor.setVisible(true);

        // Has the user decided to proceed with the modifications?
        if (editor.isEmployeeConfirmed()) {

            // Commit the employee changes to the database
            entityManager.getTransaction().begin();
            entityManager.merge(selectedEmployee);
            entityManager.getTransaction().commit();
            
        } else {
            // Rollback any changes by refrreshing the employee record
            entityManager.refresh(selectedEmployee);
        }
    }

    @Action(enabledProperty = "employeeSelected")
    @SuppressWarnings("unchecked")
    public void deleteEmployeeButton() {

        if (JOptionPane.showConfirmDialog(this,
                "Are you sure you wish to delete the employee",
                "Delete Employee",
                JOptionPane.YES_NO_OPTION,
                JOptionPane.WARNING_MESSAGE) != JOptionPane.YES_OPTION) {
            return;
        }

        // Mark the employee as deleted
        entityManager.getTransaction().begin();
        selectedEmployee.setAuthorisationLevel(AuthorisationLevel.DELETED);
        entityManager.getTransaction().commit();

        // Refresh the list
        employeeList.clear();
        employeeList.addAll((List<Employee>)employeeQuery.getResultList());
    }

    @Action(enabledProperty = "supervisorLoggedIn")
    @SuppressWarnings("unchecked")
    public void newEmployeeButton() {

        // Create a new employee record and throw it into the editor
        Employee newEmployee = new Employee();
        EmployeeEditor editor = new EmployeeEditor(this, true);
        editor.setCurrentRecord(newEmployee);
        editor.setVisible(true);

        // If the user bottled it then just bail out
        if (!editor.isEmployeeConfirmed()) {
            return;
        }

        try {
            // Persist the new employee
            entityManager.getTransaction().begin();
            entityManager.persist(newEmployee);
            entityManager.flush();

            // Add a default working pattern master
            WorkingSummary newWorkingPatternMaster =
                    new WorkingSummary();
            newWorkingPatternMaster.setEmployeeId(
                    newEmployee.getEmployeeId());
            newEmployee.setWorkingPatterns(
                    newWorkingPatternMaster);

            entityManager.persist(newEmployee);
            entityManager.persist(newWorkingPatternMaster);
            entityManager.flush();

            entityManager.getTransaction().commit();

            // Refresh the employee record to pick up any collections
            entityManager.refresh(newWorkingPatternMaster);
            entityManager.refresh(newEmployee);

        } catch (RuntimeException e) {
            LOGGER.log(Level.SEVERE, "Error creating employee", e);
            ErrorDialog.showError(this, e);
            if (entityManager.getTransaction().isActive()) {
                entityManager.getTransaction().rollback();
            }
        }

        // Refresh the list
        employeeList.clear();
        employeeList.addAll((List<Employee>)employeeQuery.getResultList());

        // Select the newly created row
        for (int row = 0; row < employeeTable.getRowCount(); row++) {

            if (employeeTable.getValueAt(row, 0).
                    equals(newEmployee.getEmployeeId())) {

                employeeTable.scrollRectToVisible(
                        employeeTable.getCellRect(row, 0, true));
                employeeTable.setRowSelectionInterval(row, row);
            }
        }
    }

    @Action(enabledProperty = "employeeSelected")
    public void editContractSummary() {
        
        WorkingSummaryEditor editor = new WorkingSummaryEditor(this, true);
        editor.setCurrentRecord(selectedEmployee.getWorkingPatternsMaster());
        editor.setVisible(true);

        // Save changes?
        if (editor.isWorkingPatternConfirmed()) {
            
//            // Merge the changes back to the database
//            EventLogging.LogEvent(new Date(), selectedEmployee,
//                    EventLogging.EVENT_TYPE_WORKING_PATTERN_MODIFIED,
//                    entityManager);

            Event logEntry = new Event();
            logEntry.setEmployeeId(selectedEmployee);
            logEntry.setEventType(EventType.WORKING_PATTERN_MODIFIED);
            logEntry.setEventTime(new Date());

            entityManager.getTransaction().begin();
            entityManager.persist(logEntry);
            entityManager.merge(selectedEmployee.getWorkingPatternsMaster());
            entityManager.getTransaction().commit();

        } else {

            // Refresh the modified record from the database
            entityManager.refresh(selectedEmployee.getWorkingPatternsMaster());
        }
    }

    @Action(enabledProperty = "workingPatternDetailSelected")
    public void editPeriodButton() {

        // Now edit the required values into the records
        WorkingPatternEditor editor = new WorkingPatternEditor(
                this, getSelectedWorkingPatternDetail(), selectedEmployee);
        editor.setVisible(true);

        // Save changes?
        if (editor.getSaved()) {

            Event logEntry = new Event();
            logEntry.setEmployeeId(selectedEmployee);
            logEntry.setEventType(EventType.WORKING_PATTERN_MODIFIED);
            logEntry.setEventTime(new Date());

            entityManager.getTransaction().begin();
            entityManager.persist(logEntry);
            entityManager.merge(getSelectedWorkingPatternDetail());

            System.out.println("Here");
            System.out.println(getSelectedWorkingPatternDetail().getEmployees());

            // Reassess the working pattern master and persist if required
            if (new EmployeeUtilities().assessPatternMaster(
                    getSelectedWorkingPatternDetail().
                    getEmployees().getWorkingPatternsMaster())) {

                entityManager.merge(getSelectedWorkingPatternDetail().
                        getEmployees().getWorkingPatternsMaster());
            }

            PeriodCalculations.reassessAndPersistWorkingDays(
                    entityManager, selectedEmployee, null);

            entityManager.getTransaction().commit();

        } else {
            
            // Refresh the modified record from the database
            entityManager.refresh(getSelectedWorkingPatternDetail());
        }
        
        editor.dispose();
    }

    @Action(enabledProperty = "employeeSelected")
    public void newPeriodButton() {

        // Get a couple of convenient local variables (cuts down on verbose code)

        WorkingSummary patternMaster =
                selectedEmployee.getWorkingPatternsMaster();

        List<WorkingPattern> patternDetailsList =
                selectedEmployee.getWorkingPatterns();

        // Create a new pattern and associated it with the employee
        WorkingPattern newPattern = new WorkingPattern(
                selectedEmployee.getEmployeeId(),
                (short)(patternMaster.getNumberOfPeriods() + 1));

        // Allow the user to enter details of the employee
        WorkingPatternEditor editor =
                new WorkingPatternEditor(this, newPattern, selectedEmployee);
        editor.setVisible(true);

        // If the user bottled it then just bail out
        if (!editor.getSaved()) {
            return;
        }

        Event logEntry = new Event();
        logEntry.setEmployeeId(selectedEmployee);
        logEntry.setEventType(EventType.WORKING_PATTERN_MODIFIED);
        logEntry.setEventTime(new Date());

        // Advance the period no
        short nextPeriodIndex = patternMaster.getNumberOfPeriods();
        nextPeriodIndex++;
        patternMaster.setNumberOfPeriods(nextPeriodIndex);

        // Persist the new pattern and add it to our employeeList
        entityManager.getTransaction().begin();

        entityManager.persist(logEntry);
        entityManager.persist(newPattern);

        selectedEmployee.getWorkingPatterns().add(newPattern);
        new EmployeeUtilities().assessPatternMaster(patternMaster);
        entityManager.merge(patternMaster);
        entityManager.flush();
        
        entityManager.refresh(selectedEmployee);

        PeriodCalculations.reassessAndPersistWorkingDays(
                entityManager, selectedEmployee, null);

        entityManager.getTransaction().commit();

        // Flick the selected employee off/on to force a refresh
        Employee tempEmployee = getSelectedEmployee();
        setSelectedEmployee(null);
        setSelectedEmployee(tempEmployee);

//        EventLogging.LogEvent(new Date(),
//                selectedEmployee,
//                EventLogging.EVENT_TYPE_WORKING_PATTERN_MODIFIED,
//                entityManager);
    }

    @Action(enabledProperty = "workingPatternDetailSelected")
    public void deletePeriodButton() {

        if (JOptionPane.showConfirmDialog(this,
                "Are you sure you wish to delete the working pattern",
                "Delete Working Pattern",
                JOptionPane.YES_NO_OPTION,
                JOptionPane.WARNING_MESSAGE) != JOptionPane.YES_OPTION) {
            return;
        }

        // Remove the pattern from the working pattern nmaster        
        getSelectedEmployee().getWorkingPatterns().
                remove(getSelectedWorkingPatternDetail());

        // Remove the actual working pattern
        entityManager.getTransaction().begin();

        entityManager.remove(getSelectedWorkingPatternDetail());

        // Reassess the working pattern master and persist if required
        if (new EmployeeUtilities().assessPatternMaster(
                getSelectedWorkingPatternDetail().
                getEmployees().getWorkingPatternsMaster())) {
            
            entityManager.merge(
                    getSelectedWorkingPatternDetail().
                    getEmployees().getWorkingPatternsMaster());
        }

        PeriodCalculations.reassessAndPersistWorkingDays(
                entityManager, selectedEmployee, null);

        entityManager.getTransaction().commit();

        // Force a refresh of the employee
        Employee tempEmployee = getSelectedEmployee();
        setSelectedEmployee(null);
        setSelectedEmployee(tempEmployee);
    }

    @SuppressWarnings("unchecked")
    @Action
    public void includeDeletedClicked() {

        if (includeDeletedButton.isSelected()) {
            employeeQuery = allEmployeesQuery;
        } else {
            employeeQuery = activeEmployeesQuery;
        }

        employeeList.clear();
        employeeList.addAll((List<Employee>)employeeQuery.getResultList());
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private TimeRecording.forms.AbsenceSummaryPanel absenceSummaryPanel;
    private javax.persistence.Query activeEmployeesQuery;
    private javax.swing.JCheckBox alertsSuppressedCheckBox;
    private javax.persistence.Query allEmployeesQuery;
    private javax.swing.JFormattedTextField annualLeaveDays;
    private javax.swing.JLabel annualLeaveDaysLabel;
    private javax.swing.JFormattedTextField annualLeaveHours;
    private javax.swing.JLabel annualLeaveHoursLabel;
    private TimeRecording.enums.AuthorisationLevelConverter authorisationLevelConverter;
    private javax.swing.JLabel authorisationLevelLabel;
    private javax.swing.JTextField authorisationLevelText;
    private javax.swing.JLabel badgesLabel;
    private javax.swing.JPanel contractPanel;
    private javax.swing.JFormattedTextField contractedPeriodField;
    private TimeRecording.forms.renderers.DateCellRenderer dateCellRenderer;
    private javax.swing.JButton deleteEmployeeButton;
    private javax.swing.JButton deletePeriodButton;
    private javax.swing.JButton editEmployeeButton;
    private javax.swing.JButton editPatternButton;
    private javax.swing.JButton editPeriodButton;
    private javax.swing.JPanel employeeButtonPanel;
    private java.util.List<TimeRecording.tables.Employee> employeeList;
    private javax.persistence.Query employeeQuery;
    private TimeRecording.enums.EmployeeStatusConverter employeeStatusConverter;
    private javax.swing.JTable employeeTable;
    private javax.swing.JPanel employeesPanel;
    private javax.persistence.EntityManager entityManager;
    private javax.swing.JCheckBox flexitimeCheckBox;
    private javax.swing.JLabel forenameLabel;
    private javax.swing.JTextField forenameText;
    private javax.swing.JFormattedTextField hoursPerDay;
    private javax.swing.JLabel hoursPerDayLabel;
    private javax.swing.JLabel hoursPerWeekLabel;
    private javax.swing.JToggleButton includeDeletedButton;
    private javax.swing.JList jList1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane masterScrollPane;
    private javax.swing.JButton newEmployeeButton;
    private javax.swing.JButton newPeriodButton;
    private javax.swing.JPanel patternButtonPanel;
    private javax.swing.JTextArea patternDescriptionTextArea;
    private javax.swing.JScrollPane patternScrollPane;
    private javax.swing.JLabel payrollReferenceLabel;
    private javax.swing.JTextField payrollReferenceText;
    private javax.swing.JLabel statusLabel;
    private javax.swing.JTextField statusText;
    private javax.swing.JLabel surnameLabel;
    private javax.swing.JTextField surnameText;
    private TimeRecording.forms.renderers.TimeCellRenderer timeCellRenderer;
    private javax.swing.JLabel usernameLabel;
    private javax.swing.JTextField usernameText;
    private javax.swing.JScrollPane workingPatternPane;
    private javax.swing.JPanel workingPatternPanel;
    private javax.swing.JTable workingPatternTable;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

    private TimeRecordingView myParent;
}
